package com.whz.generic.serializer;

import org.springframework.cache.support.NullValue;

import java.util.Objects;

/**
 * 序列化方式的抽象实现
 */
abstract class AbstractRedisSerializer implements Serializer<Object> {
    private byte[] nullValueBytes;

    /**
     * 获取空值的序列化值
     *
     * @return byte[]
     */
    byte[] getNullValueBytes() {
        if (Objects.isNull(nullValueBytes)) {
            synchronized (this) {
                if (Objects.isNull(nullValueBytes)) {
                    nullValueBytes = serialize(NullValue.INSTANCE);
                }
            }
        }
        return nullValueBytes;
    }
}